package com.yitiao.base.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileDemo {
    public static void main(String[] args) throws IOException {
//        try {
        File file = new File("./1.json");
        file.createNewFile();
        file.setWritable(true);

//            BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getPath()), StandardCharsets.UTF_8);
        BufferedWriter writer = new BufferedWriter(new FileWriter(file.getPath()));
        writer.write("{'id':'2'}");
        writer.close(); // 一定要close才可以写入
//            Files.write(Paths.get(file.getPath()), "123".getBytes());

//            file.delete();
//        } catch (Exception e) {
//            System.out.println(e.getMessage());
//            throw new RuntimeException(e);
//        }

    }
}
